package com.personal.sfe.office;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.URLUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

/**
 * @author: 梁奔
 * @date: 2025/11/05
 */

@RestController
public class ExcelController {

    @GetMapping(value = "/djdfmb/download")
    public void  download(HttpServletResponse response) throws IOException {
        InputStream inputStream = getClass().getResourceAsStream("/templates/djdf.xlsx");
        String fileName = "党费缴纳导入模板";
        response.setContentType("application/vnd.ms-excel");
        String encodedFileName = URLUtil.encode(fileName, StandardCharsets.UTF_8);
        String contentDisposition = "attachment; filename="+encodedFileName+".xlsx";
        response.setHeader("Content-Disposition", contentDisposition);
        IoUtil.copy(inputStream, response.getOutputStream());
        IoUtil.close(inputStream);
    }


}
